var e = require;
var t = module;
var o = exports;
var n = o;
Object.defineProperty(n, "__esModule", {value: !0}), (n.GameState = n.GameModel = n.SnakeType = n.FoodType = void 0);
var i,
    a,
    r,
    s = e("Util");
((r = n.FoodType || (n.FoodType = {})).FirstFood = "最大食物"),
    (r.SecondFood = "普通食物"),
    (r.ThirdFood = "最小食物"),
    (r.DieFood = "死亡食物"),
    (r.Shit = "屎"),
    (r.Magnet = "磁铁"),
    (r.Double = "双倍"),
    (r.Missile = "导弹"),
    (r.Shield = "护盾"),
    (r.Stars = "星星"),
    (r.StoreFood = "宝藏屋食物"),
    (function (e) {
        (e[(e.None = 0)] = "None"),
            (e[(e.Player = 1)] = "Player"),
            (e[(e.Other = 2)] = "Other"),
            (e[(e.AI = 3)] = "AI");
    })(n.SnakeType || (n.SnakeType = {})),
    (function (e) {
        (e.TimeLimit = "限时模式"), (e.endless = "无尽模式"), (e.eatChicken = "吃鸡模式"), (e.teamGame = "团队模式");
    })((i = n.GameModel || (n.GameModel = {}))),
    (function (e) {
        (e[(e.ready = 0)] = "ready"),
            (e[(e.play = 1)] = "play"),
            (e[(e.stop = 2)] = "stop"),
            (e[(e.finish = 3)] = "finish");
    })((a = n.GameState || (n.GameState = {})));
var c = function (e, t) {
        (this.snakeName = e), (this.fraction = t);
    },
    l = (function () {
        function e() {
            (this.againPlayTimes = 0),
                (this.size = cc.rect(0, 0, 3072, 1728)),
                (this.UserName = "获取中..."),
                (this.OldUserSkin = null),
                (this.UserSkin = 0),
                (this.initlength = 0),
                (this.eatSize = 0),
                (this.profit = 1),
                (this.PlayerCoin = 0),
                (this.PlayerEgg = 0),
                (this.RankingDataList = []),
                (this.SelfPlayerData = null),
                (this.HighestScoreInHistory_TimeLimit = "无"),
                (this.HighestScoreInHistory_endless = "无"),
                (this.HighestScoreInHistory_shooting = "无"),
                (this.GameModel = i.endless),
                (this.themeIndex = 1),
                (this.tt_recorder_flags = !1),
                (this.oppo_ad_index = 0),
                (this.CoinTipIndex = 100),
                (this.gameState = a.ready),
                (this.isStoreHose = !1),
                (this.isIncome = !1);
        }
        return (
            Object.defineProperty(e, "instance", {
                get: function () {
                    return e._instance || (e._instance = new e()), e._instance;
                },
                enumerable: !1,
                configurable: !0
            }),
            (e.prototype.getUserSkin = function () {
                var e = Number(s.default.getItem("gooutIndex", "0"));
                return (this.UserSkin = e), e;
            }),
            (e.prototype.setUserSkin = function (e) {
                s.default.setItem("gooutIndex", e.toString()), (this.UserSkin = e);
            }),
            (e.prototype.getPlayerCoin = function () {
                return (
                    0 == this.PlayerCoin && (this.PlayerCoin = Number(s.default.getItem("PlayerCoin", "0"))),
                    this.PlayerCoin
                );
            }),
            (e.prototype.setPlayerCoin = function (t) {
                (this.PlayerCoin = t),
                    s.default.setItem("PlayerCoin", this.PlayerCoin.toString()),
                    game.appFacade.sendNotification(e.UPDATE_PLAYERCOIN, {});
            }),
            (e.prototype.getPlayerEgg = function () {
                return this.PlayerEgg;
            }),
            (e.prototype.setPlayerEgg = function (e) {
                (this.PlayerEgg = e), s.default.setItem("PlayerEgg", this.PlayerEgg.toString());
            }),
            (e.prototype.setUserFraction = function (t, o, n) {
                if ((void 0 === n && (n = !1), "0" != o.toString()))
                    if (n) {
                        for (var a = 0; a < this.RankingDataList.length; a++)
                            if ((d = this.RankingDataList[a]).snakeName == t) {
                                this.RankingDataList.splice(a, 1);
                                break;
                            }
                    } else {
                        if (t == e.instance.UserName)
                            if (
                                (this.SelfPlayerData.snakeName,
                                (this.SelfPlayerData.fraction = o),
                                this.GameModel == i.endless)
                            ) {
                                var r = s.default.getItem("HighestScoreInHistory_endless", "0");
                                o > Number(r) &&
                                    (s.default.setItem("HighestScoreInHistory_endless", o.toString()),
                                    (this.HighestScoreInHistory_endless = o.toString()));
                            } else
                                this.GameModel == i.eatChicken
                                    ? ((r = s.default.getItem("HighestScoreInHistory_shooting", "0")),
                                      o > Number(r) &&
                                          (s.default.setItem("HighestScoreInHistory_shooting", o.toString()),
                                          (this.HighestScoreInHistory_shooting = o.toString())))
                                    : this.GameModel == i.TimeLimit &&
                                      ((r = s.default.getItem("HighestScoreInHistory_TimeLimit", "0")),
                                      o > Number(r) &&
                                          (s.default.setItem("HighestScoreInHistory_TimeLimit", o.toString()),
                                          (this.HighestScoreInHistory_TimeLimit = o.toString())));
                        var l = !0;
                        for (a = 0; a < this.RankingDataList.length; a++) {
                            var d;
                            (d = this.RankingDataList[a]).snakeName == t && ((l = !1), (d.fraction = o));
                        }
                        if (l) {
                            var u = new c(t, o);
                            this.RankingDataList.push(u);
                        }
                        for (var p = 0; p < this.RankingDataList.length; p++)
                            for (var h = this.RankingDataList[p], f = p + 1; f < this.RankingDataList.length; f++) {
                                var _ = this.RankingDataList[f];
                                if (h.fraction < _.fraction) {
                                    var y = h.snakeName,
                                        m = h.fraction;
                                    (h.snakeName = _.snakeName),
                                        (h.fraction = _.fraction),
                                        (_.snakeName = y),
                                        (_.fraction = m);
                                }
                            }
                        this.RankingDataList.length > 10 && this.RankingDataList.splice(10, 1);
                    }
            }),
            (e.prototype.getOppoShowAd = function () {
                return this.oppo_ad_index++, this.oppo_ad_index % 3 == 1;
            }),
            (e.prototype.ResetData = function () {
                (this.RankingDataList = []),
                    (this.SelfPlayerData = new c(e.instance.UserName, 0)),
                    (this.HighestScoreInHistory_TimeLimit = s.default.getItem("HighestScoreInHistory_TimeLimit", "无")),
                    (this.HighestScoreInHistory_endless = s.default.getItem("HighestScoreInHistory_endless", "无")),
                    (this.HighestScoreInHistory_shooting = s.default.getItem("HighestScoreInHistory_shooting", "无")),
                    (this.PlayerCoin = Number(s.default.getItem("PlayerCoin", "0"))),
                    (this.PlayerEgg = Number(s.default.getItem("PlayerEgg", "0"))),
                    (this.UserSkin = Number(s.default.getItem("gooutIndex", "0")));
            }),
            (e.prototype.getCoinTipIndex = function () {
                return (
                    s.default.getItem("GetCoinTipTimer", "000") != s.default.getTodayStr() &&
                        (s.default.setItem("GetCoinTipTimer", s.default.getTodayStr()),
                        s.default.setItem("GetCoinTipIndex", "100")),
                    Number(s.default.getItem("GetCoinTipIndex", "100"))
                );
            }),
            (e.prototype.setCoinTipIndex = function (e) {
                s.default.setItem("GetCoinTipIndex", e.toString());
            }),
            (e._instance = null),
            (e.UPDATE_PLAYERCOIN = "UPDATE_PLAYERCOIN"),
            e
        );
    })();
n.default = l;
